<?php
require_once 'init.php';

set_time_limit(0);

$update_frequency = date('H');

$page_db = new Core_Model_DbTable_Pages();

$script_name = "update_single_page.php";
$offset = 0;

while (true) {
    $thread_count = countThread($script_name);
    $page_count = MAX_THREAD - $thread_count;
    if ($page_count > 0) {
        $pages = $page_db->getPagesForUpdating($update_frequency, $page_count, $offset);
        $offset += $page_count;
        if ($pages->count() > 0) {
            foreach ($pages as $page) {
                exec("php " . SCRIPT_PATH . "/$script_name \"{$page->id_social_page}\" > /dev/null &");
            }
        } else {
            break;
        }
    } else {
        sleep(60);
    }
}

?>
